//
//  TourOrderDetailViewController.m
//  EasyToTesco2.0
//
//  Created by knew on 2017/5/8.
//  Copyright © 2017年 EasyToTesco. All rights reserved.
//

#import "TourOrderDetailViewController.h"

#import "GoodsOrderDetailsFirstCell.h"

#import "GoodsOrderDetailsSecondCell.h"
#import "GoodsOrderDetailsThirdCell.h"
#import "ConfirmView.h"
#import "OrderPaymentController.h"

@interface TourOrderDetailViewController ()<UITableViewDelegate,UITableViewDataSource,ConfirmViewOrderDelagate>

{
    MBProgressHUD *progressHUD;
    ConfirmView *lastView;
}

@property(nonatomic,strong)UITableView *orderDetailsView;


@end

@implementation TourOrderDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self bulidView];
    
}


- (void)bulidView
{
    self.view.backgroundColor = BACKGROUND_COLOR;
    self.title = @"订单详情";
    
    _orderDetailsView = [[UITableView alloc] initWithFrame:CGRectMake(0,0,WIDTH, HEIGHT-HEIGHT/9-55) style:UITableViewStylePlain];
    [self.view addSubview:_orderDetailsView];
    _orderDetailsView.backgroundColor = BACKGROUND_COLOR;
    _orderDetailsView.delegate = self;
    _orderDetailsView.dataSource = self;
    _orderDetailsView.showsVerticalScrollIndicator = NO;
    
}

- (void)setStutas_zt:(NSString *)stutas_zt
{
    _stutas_zt  = stutas_zt;
    
    if ([_stutas_zt isEqualToString:@"0"]) {
        lastView = [[ConfirmView alloc] initWithFrame:CGRectMake(0,HEIGHT * 0.8,WIDTH,HEIGHT/9)];
        lastView.delegate = self;
        [self.view addSubview:lastView];
    }
}

#pragma mark 确认下单
- (void)confirmViewOrderDidClick:(UIButton *)button
{
    OrderPaymentController *OrderPaymentVC = [[OrderPaymentController alloc] init];
    OrderPaymentVC.OrderTitleString = @"商品订单";
    OrderPaymentVC.OrderDescribeInfo = @"商品订单";
    OrderPaymentVC.orderType = @"4";
    
    OrderPaymentVC.OrderString = self.goodsOrderModel.order_no;
    OrderPaymentVC.OrderMonryString = self.goodsOrderModel.pay_amount;
    [self.navigationController pushForm:self.navigationController pushToAndHidden:OrderPaymentVC];
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 3;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if (indexPath.section == 0) {
        
        static NSString *identifier= @"firstCellOrder";
        GoodsOrderDetailsFirstCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
        if (cell==nil) {
            
            cell = [[GoodsOrderDetailsFirstCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
        }
        
        lastView.totalPrice.text = [NSString stringWithFormat:@"总计:%@元",self.goodsOrderModel.pay_amount];
        lastView.totalPrice.font = FONT(15);
        lastView.totalPrice.font = [UIFont boldSystemFontOfSize:15];
        
        cell.NameLabel.text = [NSString stringWithFormat:@"取票人姓名: %@",self.goodsOrderModel.realname];
        cell.AddressLabel.text = [NSString stringWithFormat:@"取票人手机号:%@",self.goodsOrderModel.mobile];
        return cell;
        
    }else if(indexPath.section == 2){
        
        GoodsOrderDetailsThirdCell *cell = [[GoodsOrderDetailsThirdCell alloc] init];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.orderIdLabel.text = [NSString stringWithFormat:@"订单编号: %@",self.goodsOrderModel.order_no];
        cell.timeLabel.text = [NSString stringWithFormat:@"提交时间: %@",self.goodsOrderModel.create_time];
        
        return cell;
        
    }else{
        
        static NSString *identifier= @"ListsCellOrder";
        GoodsOrderDetailsSecondCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
        if (cell==nil) {
            
            cell = [[GoodsOrderDetailsSecondCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
        }
        
//        GoodsListsModel *goodsListsModel = listArr[indexPath.section-1];
//        cell.goodsImg.image = [UIImage imageNamed:@"goodsLoadJGG.jpg"];
        
#warning  图片
        [cell.goodsImg sd_setImageWithURL:[NSURL URLWithString:self.goodsOrderModel.picurl] placeholderImage:[UIImage imageNamed:@"goodsLoadJGG"]];
        
        
        cell.goodsNameLabel.text = self.goodsOrderModel.title;
        cell.guigeLabel.text = [NSString stringWithFormat:@"使用时间:%@",self.goodsOrderModel.travel_date];
        
        cell.kuaidiLabel.text = @"取票码：";
        cell.freeLabel.text = self.goodsOrderModel.password;
        cell.priceLabel.text = [NSString stringWithFormat:@"¥ %@",self.goodsOrderModel.price];
        cell.numLabel.text = [NSString stringWithFormat:@"x %@",self.goodsOrderModel.ticket_count];
        cell.totalLabel.text = [NSString stringWithFormat:@"¥ %@",self.goodsOrderModel.pay_amount];
        
        return cell;
        
    }
    
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    if (indexPath.section == 0) {
        return 60;
    }else if (indexPath.section == 2){
        return 55;
    }else{
        return 175;
    }
    
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    if (section == 0) {
        return 0.01;
    }else{
        return 10;
    }
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 0.01;
}


@end
